home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 301-325 / disk_319 / cnewssrc / cnews.orig.lzh / relay / hdrparse.c < prev    next >
C/C++ Source or Header  |  1989-06-27  |  2KB  |  90 lines

  1. /*
  2.  * Usenet header parsing and remembering.
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <ctype.h>
  7. #include <sys/types.h>
  8. #include "libc.h"
  9. #include "news.h"
  10. #include "headers.h"
  11. #include "hdrint.h"
  12.  
  13. /*
  14.  * Reset internal state of header parser.
  15.  * (Empty the stomach of partially-digested headers.)
  16.  */
  17. void
  18. hdrwretch()
  19. {
  20.     /* historical stub */
  21. }
  22.  
  23. /*
  24.  * Parse RFC822/850/1036 header into "hdrs".  Retain significant values.
  25.  * Assumes ishdr has been called first.
  26.  *
  27.  * If a keyword matches one in hdrlst, store the value in *malloc'ed memory*
  28.  * (N.B.).  freeheader() will free this memory.
  29.  */
  30. void
  31. hdrparse(hdrs, line, hdrlst)
  32. register struct headers *hdrs;
  33. register char *line;
  34. hdrlist hdrlst;                /* headers of positive utility */
  35. {
  36.     register struct hdrdef **hpp;
  37.  
  38.     for (hpp = hdrlst; *hpp != NULL; hpp++)
  39.         if (STREQN(line, (*hpp)->hdrnm, (int)(*hpp)->hdrlen) &&
  40.             (*hpp)->hdroff >= 0) {    /* paranoia */
  41.             register char **ptrp =
  42.                 (char **)((char *)hdrs+(*hpp)->hdroff);
  43.  
  44.             nnfree(ptrp);    /* free prev. val. in this art. */
  45.             *ptrp = strsave(skipsp(&line[(*hpp)->hdrlen]));
  46.             if (*ptrp != NULL)
  47.                 trim(*ptrp);    /* cut trailing \n */
  48.             break;
  49.         }
  50. }
  51.  
  52. /*
  53.  * default missing header values
  54.  *
  55.  * If strsave ever returns NULL on failure, instead of exiting,
  56.  * then the strsave calls need to check for failure.
  57.  *
  58.  * We support control message *backwards* compatibility: if no Control:
  59.  * header exists and the newsgroup matches all.all.ctl, use the Subject:
  60.  * as the control message.  Ugh.
  61.  */
  62. void
  63. hdrdeflt(hdrs)
  64. register struct headers *hdrs;
  65. {
  66.     if (hdrs->h_ngs == NULL)
  67.         hdrs->h_ngs = strsave(JUNK);
  68.     if (hdrs->h_distr == NULL)
  69.         hdrs->h_distr = strsave(DEFDIST);
  70.     if (hdrs->h_msgid == NULL && hdrs->h_artid != NULL)    /* obs. art.id. */
  71.         hdrs->h_msgid = strsave(hdrs->h_artid);
  72.     if (hdrs->h_msgid == NULL)
  73.         hdrs->h_msgid = strsave(DEFMSGID);
  74.     if (hdrs->h_msgid[0] == '\0') {
  75.         free(hdrs->h_msgid);
  76.         hdrs->h_msgid = strsave(DEFMSGID);
  77.     }
  78.     if (hdrs->h_expiry == NULL)
  79.         hdrs->h_expiry = strsave(DEFEXP);
  80.     if (hdrs->h_expiry[0] == '\0') {
  81.         free(hdrs->h_expiry);
  82.         hdrs->h_expiry = strsave(DEFEXP);
  83.     }
  84.     if (hdrs->h_subj == NULL)
  85.         hdrs->h_subj = strsave("");
  86.  
  87.     if (hdrs->h_ctlcmd == NULL && oldctl(hdrs))
  88.         hdrs->h_ctlcmd = strsave(hdrs->h_subj);
  89. }
  90.